package cn.meizhu.org.controller;

import cn.meizhu.org.domain.Shop;
import cn.meizhu.org.domain.Systype;
import cn.meizhu.org.query.ShopQuery;
import cn.meizhu.org.query.SystypeQuery;
import cn.meizhu.org.service.IShopService;
import cn.meizhu.org.service.ISystypeService;
import cn.meizhu.util.AjaxResult;
import cn.meizhu.util.QueryResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/systype")
@RestController
@Api(tags = "数据字典维护接口")
//@CrossOrigin
public class SystypeController {

    @Autowired
    private ISystypeService systypeService;


    @PutMapping
    @ApiOperation(value = "数据字典添加或者修改", notes = "有id就是修改，没有id就是新增")
    public AjaxResult addAndUpdDepartment(@RequestBody Systype systype){
        try {
            if (systype.getId() == null){
                systypeService.save(systype);
            }else {
                systypeService.update(systype);
            }
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage(e.getMessage());
        }
    }


    @DeleteMapping("/{id}")
    @ApiOperation(value = "这是数据字典删除")
    public AjaxResult delDepartmentById(@PathVariable("id") Long id){
        try {
            systypeService.delete(id);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage(e.getMessage());
        }
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询数据字典中指定数据")
    public Systype findDepartmentById(@PathVariable("id") Long id){
        return systypeService.findById(id);
    }

    @GetMapping
    @ApiOperation(value = "查询数据字典全部数据")
    public List<Systype> findDepartments(){
        return systypeService.findAll();
    }


    @PostMapping
    public QueryResult<Systype> queryPage(@RequestBody SystypeQuery systypeQuery){
        return systypeService.queryPage(systypeQuery);
    }



}
